#include "simulationcommands.h"

#include "../documents/data/simgraphicdata.h"

using namespace swp;

BuildSimPathCommand::BuildSimPathCommand(SimGraphicData* data,
    const QList<QUuid>& before, const QList<QUuid>& after,
    bool ignoreFirstRedo) :
        m_data(data),
        m_before(before),
        m_after(after),
        m_ignoreFirstRedo(ignoreFirstRedo)
{
    setText(QObject::tr("Sim path has changed"));
}

BuildSimPathCommand::~BuildSimPathCommand()
{

}

void BuildSimPathCommand::undo()
{
    m_data->clearSimpath();

    m_data->tryToCreateSimPath(m_before);

    m_data->emitDataChanged(); // not ideal
}

void BuildSimPathCommand::redo()
{
    if (!m_ignoreFirstRedo)
    {
        m_data->clearSimpath();

        m_data->tryToCreateSimPath(m_after);
    }

    m_ignoreFirstRedo = false;
}
